package com.px.user.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.px.user.model.ActionModel;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Generated;
import org.hibernate.annotations.GenerationTime;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import java.sql.Timestamp;
import java.util.List;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Entity(name = "room")
@ApiModel(value = "房间对象", description = "房间字段")
@org.hibernate.annotations.Table(appliesTo = "room", comment = "房间表")
@Table(indexes = {@Index(name = "adminId_index", columnList = "adminId", unique = true)})
public class Room {

    @Id
    @ApiModelProperty(value = "主键", example = "4")
    @NotNull(groups = {ActionModel.Update.class})
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Null(groups = {ActionModel.Insert.class}, message = "删除id字段")
    @Column(unique = true, nullable = false, columnDefinition = "bigint comment '主键'")
    private Long id;

    @Column(columnDefinition = "bigint comment '创建人ID'")
    @ApiModelProperty(value = "创建者ID", example = "1", hidden = true)
    private Long creatorId;

    @ApiModelProperty(value = "管理员ID", example = "1")
    @Column(columnDefinition = "bigint comment '管理员ID'")
    private Long adminId;

    @Column(columnDefinition = "varchar(512) comment '投票内容'")
    @ApiModelProperty(value = "投票内容", example = "天下集团(60000)")
    private String voteContent;

    @ApiModelProperty(value = "涨数量", example = "1")
    @Column(columnDefinition = "int default 0 comment '涨数量'")
    private Integer up;

    @ApiModelProperty(value = "跌数量", example = "2")
    @Column(columnDefinition = "int default 0 comment '跌数量'")
    private Integer down;

    @ApiModelProperty(value = "平数量", example = "2")
    @Column(columnDefinition = "int default 0 comment '平数量'")
    private Integer flat;

    @ApiModelProperty(value = "在线人数", example = "100")
    @Column(columnDefinition = "int comment '在线人数'")
    private Integer pcu;

    @Generated(GenerationTime.INSERT)
    @ApiModelProperty(value = "创建时间", hidden = true)
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP comment '创建时间'", insertable = false, updatable = false)
    private Timestamp createTime;

    @Generated(GenerationTime.INSERT)
    @ApiModelProperty(value = "更新时间", hidden = true)
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment '更新时间'", insertable = false, updatable = false)
    private Timestamp updateTime;

    /**
     * 扩展
     */
    @Transient
    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    @ApiModelProperty(value = "公告", example = "公告", hidden = true)
    private String gg;

    @Transient
    @ApiModelProperty(value = "课程列表", hidden = true)
    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    private List<Course> courses;

    @Transient
    @ApiModelProperty(value = "房管登录名", hidden = true)
    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    private String adminUsername;

    @Transient
    @ApiModelProperty(value = "房管昵称", hidden = true)
    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    private String adminNickname;

    /**
     * 扩展查询字段
     */
    @Transient
    @JsonIgnore
    @ApiModelProperty(value = "查询开始索引", hidden = true)
    private Integer startIndex;

    @Transient
    @JsonIgnore
    @ApiModelProperty(value = "查询返回数量", hidden = true)
    private Integer limit;
}
